package com.geralt.im.command;

import geralt.im.watcher.ISubject;
import geralt.im.watcher.Observer;

import java.util.LinkedList;
import java.util.Map;

import com.geralt.im.model.Message;

public abstract class Command implements ISubject{

	protected LinkedList<Observer> observers;
	protected Object object;
	protected int code;
	
	protected Map<String,Object> parameter;
	public abstract void excute();
	public Map<String, Object> getParameter() {
		return parameter;
	}
	public void setParameter(Map<String, Object> parameter) {
		this.parameter = parameter;
	}
	

	public Object getObject() {
		return object;
	}
	public void setObject(Object object) {
		this.object = object;
	}
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
		System.out.println(this.toString()+":"+code);
	}
	public Command(){
		observers = new LinkedList<Observer>();
	}
	
	@Override
	public void resgiestObserver(Observer o) {
		observers.add(o);
	}

	@Override
	public void removeObserver(Observer o) {
		int i=observers.indexOf(o);
		observers.remove(i);
	}

	@Override
	public void notifyObjservers() {
		for(int i=0;i<observers.size();++i){
			Observer observer = (Observer)observers.get(i);
			observer.update(code, object);
		}
	}
	
}
